<template>
  <div class="global h-screen">
    <div class="divItem h-[75%]">
      <button class="px-6 rounded-full text-black font-medium shadow-lg transition-all duration-300
         bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700
         transform" @click="setLeakage">
        漏气设置
      </button>
    </div>
    <div ref="terminal" class="h-[25%]">
      <textarea class="w-full h-full bg-red-100 border border-black" v-model="msg"></textarea>
    </div>

  </div>

</template>

<script setup lang="ts">
import { onMounted, ref, Ref } from 'vue'
import systemdemo from './ts/systemdemo'
import { init_turbine, 不明漏量 } from './ts/calculate'
import { 漏汽 } from './ts/leakage'

let app = window.Application
const msg = ref('')
const log = (message) => {
  const timestamp = new Date().toLocaleTimeString()
  const formattedMessage = `[${timestamp}] ${message}`
  if (msg.value.length === 0) {
    msg.value = formattedMessage
  } else {
    msg.value = `${msg.value}\n${formattedMessage}`
  }
}


function _init_(sheet = '汽机') {
  /**
   * 初始化工作表，确保存在“数据整理”和“汽机”这两个sheet。且将当前激活的sheet切换至“汽机”，同时，扫描“数据整理”sheet中的测点信息，并记录。
   * 如果不存在“数据整理”sheet，则会提示错误，如果不存在“汽机”sheet，则会自动创建。
   *
   * @type {Et.EtWorkbook}
   */

  log('初始化汽机工作表')
  // alert('初始化汽机工作表')
  let doc = app.ActiveWorkbook
  if (!doc) {
    alert('当前没有打开任何文档')
    return
  }
  // log(app.ActiveWorkbook)
  log(app.ActiveWorkbook.Sheets.Count)
  
  // if (!systemdemo.createTurbineSheet('汽机')) {
  //   return false
  // }
  // systemdemo.activate_sheet('汽机')
  // systemdemo.refreshTestPoints()
}

const setLeakage = () => {
  _init_('汽机')

  // app.Columns.AutoFit();
  // console.log("设置漏气信息")
  // console.log("新建[漏汽]sheet")

  // init_turbine();
  // 漏汽(systemdemo.getLastRowIndexOfSheet());
  // 不明漏量(systemdemo.getLastRowIndexOfSheet());
}

onMounted(() => {
  log('二次再热机组计算模块加载')
})
</script>

<style scoped></style>